<template>
  <div class="login">
    <div class="title">
      <div>鼎盛台球</div>
    </div>
    <el-form :model="loginForm" :rules="rules" status-icon ref="loginForm" label-width="100px" class="loginForm">
      <img src="@/assets/img/logo.svg" alt="" class="logo">
      <div class="label">账号:</div>
      <el-form-item prop="username">
        <el-input type="text" label="账号" placeholder="请输入账号" v-model="loginForm.username"></el-input>
      </el-form-item>
      <div class="label">密码:</div>
      <el-form-item prop="password">
        <el-input type="password" label="密码" placeholder="请输入密码" @keydown.native.enter="submitForm('loginForm')" v-model="loginForm.password"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button :class="{'not-active':!loginForm.username||!loginForm.password}" type="primary" @click="submitForm('loginForm')"> 登 录
        </el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
import { login } from "@/api/getData"

export default {
  name: "Login",
  data() {
    return {
      loginForm: {
        username: '',
        password: '',
        orgId: ''
      },
      rules: {
        username: [
          { required: true, trigger: 'blur', message: '用户名不能为空' }
        ],
        password: [
          { required: true, trigger: 'blur', message: "密码不能为空" }
        ],
      }
    }
  },
  methods: {
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          const { username, password, orgId } = this.loginForm
          login({ username, password, orgId }).then(res => {
            console.log(res)
            const data = res.data;
            this.$store.commit('SET_GTOKEN', data.token);
            this.$store.commit('SET_GACCOUNT', data.userName);
            this.$store.commit('SET_GNAME', data.realName);
            this.$store.commit('SET_GACCOUNTID', data.accountId);
            this.$router.replace("/");
            this.$message.success('登录成功')
          })
        }
      })
    }
  },
  mounted() {
  }
}
</script>

<style lang="scss" scoped>
.login {
  width: 100vw;
  height: 100vh;
  background: url("../../assets/img/login_background.svg") no-repeat;
  background-size: 100vw auto;

  .title {
    text-align: center;
    color: #0c9a8d;
    margin-bottom: calc(100vh * 0.162962963);
    padding-top: calc(100vh * 0.092592593);
    font-weight: 500;

    div:first-child {
      font-size: 30px;
      margin-bottom: calc(100vh * 0.018518519);
    }

    // div:last-child {
    // 	font-size: 14px;
    // 	opacity: 0.4;
    // }
  }

  .loginForm {
    width: 688px;
    height: 526px;
    margin: 0 auto;
    padding: 108px 100px 0 101px;
    box-sizing: border-box;
    border-radius: 10px;
    background-color: #ffffff;
    box-shadow: 0 10px 24px 0 rgba(6, 126, 126, 0.05);
    position: relative;

    .logo {
      width: 142px;
      height: 142px;
      border-radius: 50%;
      position: absolute;
      top: 0;
      left: 50%;
      transform: translate(-50%, -50%);
    }

    .not-active {
      border-color: #c4c4c4;
      background-color: #c4c4c4;
      box-shadow: 0 2px 10px 0 rgba(196, 196, 196, 0.25) !important;
    }

    .el-button {
      width: 200px;
      height: 60px;
      border-radius: 4px;
      font-size: 24px;
      font-weight: 500;
      box-shadow: 0 2px 10px 0 rgba(6, 126, 126, 0.25);
    }

    .el-input {
      width: 487px;
      height: 60px;
    }

    .label {
      font-size: 24px;
      font-weight: 500;
      color: #707070;
      margin-bottom: 20px;
    }

    /deep/ .el-form-item {
      margin-bottom: 30px;

      .el-input__inner {
        width: 487px;
        height: 60px;
        font-size: 22px;
        padding: 0 18px;
        border: 2px solid rgba(112, 112, 112, 0.2);
      }

      .el-form-item__error {
        font-size: 16px;
      }

      .el-form-item__content {
        margin: 0 !important;
        display: flex;
        align-items: center;
        justify-content: center;
      }
    }

    /deep/ .el-form-item:last-child {
      padding-top: 30px;
    }
  }
}
</style>